
#include <math.h>
#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"
#include <time.h>
#include <stdlib.h>
/*
Adventurer description: http://dominioncg.wikia.com/wiki/Adventurer

Type	Action
Effect	Reveal cards from your deck until you reveal 2 Treasure cards. Put those Treasure cards in your hand and discard the other revealed cards.
Cost	6 Coins
*/

// set NOISY_TEST to 0 to remove printfs from output

void testAdventurer()
{
 	int i, r, numPlayers, seed, choice1, choice2, choice3, player,bonus=0;
 	int deckSize, moneyCards[2], moneyValue[2], moneyPos[2]; 
 	int preDiscard, preCoins, preHand, preDeck;
 	int expectedDiscard, expectedCoins, expectedHand, expectedDeck;
 	int postDiscard, postCoins, postHand, postDeck;
 	struct gameState G;
 	int k[10];// = {curse, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall};
 	printf("Testing adventurer card\n\n");
	srand(time(NULL));
	
	//setup game
	printf("Setting up game\n");
	seed = rand(); //random seed
	k[0] = adventurer;
	for(i = 1; i < 10; i++) //random cards
	{
		k[i] = rand() % treasure_map;
	}

	numPlayers = (rand() % (MAX_PLAYERS - 1) + 2); //randomize numPlayers from 2 to max


	r = initializeGame(numPlayers, k, seed, &G);
	
	player = G.whoseTurn;//get player
	//give him a deck of random cards
	deckSize = rand() % (MAX_DECK-5) + 5;
	G.deckCount[player] = deckSize;
	for (i = 0; i < deckSize; i++)
	{
		G.deck[player][i]=rand() % (treasure_map - adventurer) + adventurer;
	}
	printf("Deck size: %d\n", deckSize);

	//make random money
	for (i = 0; i < 2; i++)
	{
		moneyCards[i] = rand() % (gold - copper) + copper;
		if (moneyCards[i] == copper)
			moneyValue[i] = 1;
		if (moneyCards[i] == silver)
			moneyValue[i] = 2;
		if (moneyCards[i] == gold)
			moneyValue[i] = 3;
	}

	//put adventurer in hand
	//G.hand[player][0] = adventurer;
	buyCard(great_hall, &G);
		
	//put money in deck
	moneyPos[0] = rand() % (deckSize -2) +1;
	moneyPos[1] = rand() % (deckSize - moneyPos[0]) + moneyPos[0];
	G.deck[player][ moneyPos[0] ] = moneyCards[0];
	G.deck[player][ moneyPos[1] ] = moneyCards[1];
	printf("Treasure type %d in deck position %d\n", moneyCards[0], moneyPos[0]);
		printf("Treasure type %d in deck position %d\n", moneyCards[1], moneyPos[1]);

	//get pre values
	updateCoins(player, &G, bonus);
	preDiscard = G.discardCount[player];
	preCoins = G.coins;
	preHand = G.handCount[player];
	preDeck = G.deckCount[player];
    

	//play the card
	cardEffect(adventurer,0,0,0, &G, 0, &bonus);
	updateCoins(player, &G, bonus);

	//check number of coins
	printf("\nChecking values");

	expectedCoins = preCoins + moneyValue[0] + moneyValue[1];
	postCoins = G.coins;
	printf("\nExpected coins:%d\tActual coins:%d ", expectedCoins, postCoins);
	if(expectedCoins == postCoins){
		printf("PASS\n");
	}
	else
	{
		printf("FAIL\n");
	}
	expectedDeck = deckSize - 2;

	expectedDiscard = preDiscard + moneyPos[1] +1 - 2;
	printf("\nExpected discard size=%d\tActual discard size=%d ",expectedDiscard , G.discardCount[player]);
	if(expectedDiscard == G.discardCount[player]){
		printf("PASS\n");
	}
	else
	{
		printf("FAIL\n");
	}

	expectedHand = preHand + 2 - 1;
	printf("\nExpected hand size:%d\tActual hand size:%d ", expectedHand, G.handCount[player]);	
	if(expectedHand == G.handCount[player]){
		printf("PASS\n");
	}
	else
	{
		printf("FAIL\n");
	}


}

int main()
{
	testAdventurer();
	return 0;
}